/**********************************************************************
Compile : gcc -O3 -o filter filter.c
Usage : ./filter N L filename
N     : number of the nodes
L     : number of the steps
**********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void print_help ()
{
	printf ("Usage         : ./filter N L filename\n");
	printf ("                (./filter 6 8 N-6x8-S)\n");
	printf ("N             : number of the nodes\n");
	printf ("L             : number of the steps\n");
	printf ("filename      : input feasible processes\n");
}

int main (int argc, char *argv[])
{
	FILE *fp;
	char buf[256], comment[256];
	int N, L, i, j, flag;

	if (argc == 1)
	{
		print_help ();
		exit (0);
	}

	N = atoi (argv[1]);
	L = atoi (argv[2]);

	int pathway[L][N];

	fp = fopen (argv[3], "r");
	while (fgets (comment, 256, fp))
	{
		for (i = 0; i < L; i++)
		{
			for (j = 0; j < N; j++)
			{
				fscanf (fp, "%d", &pathway[i][j]);
			}
			fgets (buf, 256, fp);
		}

		flag = 1;
		for (i = 0; i < N; i++)
		{
			int tmp;

			tmp = 0;
			for (j = 0; j < L; j++)
			{
				tmp += pathway[j][i];
			}

			if (tmp == 0 || tmp == L)
			{
				flag = 0;
				break;
			}
		}

		if (flag == 1)
		{
			printf ("%s", comment);
			for (i = 0; i < L; i++)
			{
				for (j = 0; j < N; j++)
				{
					printf ("%d ", pathway[i][j]);
				}
				printf ("\n");
			}
		}
	}
	fclose (fp);
}
